﻿using System;
using System.IO;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using QzEbook.AccessObject;
using QzEbook.BaseView;
using QzEbook.Common;
using QzEbook.Common.Emum;


namespace qzEbook.webUI
{
    public partial class UserPane : UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["ActiveViewIndex"] != null)
            {
                MultiPlace.ActiveViewIndex = (Int32)Session["ActiveViewIndex"];
            }
            bindData();
        }

        /// <summary>
        /// 重写菜单 ;
        /// </summary>
        /// <returns></returns>
        protected override bool canBuildNav()
        {
            this.navType = NavType.USERPANE;
            return base.canBuildNav();
        }

        private void bindData()
        {
            SiteUser userInfo = new SiteUser();
            userInfo.Uid = userSession.Uid;
            userInfo=userInfo.select();

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("<h3>");
            sb.AppendFormat("<img id=\"uploadicon\" src=\"../{1}noset.gif\" alt=\"点击更改个性头像\">:{0}  ", userInfo.Name,Config.UserBookSavePath);
            sb.AppendFormat("<a href='../Feed.xhtml?Uid={0}'><img src='../images/icon_feed.gif' alt='订阅{0}Rss源' /></a></h3>",userInfo.Uid);
            sb.AppendLine("</h3>");
            sb.Append("<dl>");
            sb.AppendFormat("<dt>权限:</dt><dd>{0}级编辑</dd>", userInfo.LevelName);
            sb.AppendFormat("<dt>空间(花费/配额):</dt><dd>{0}M/{1}M</dd>", userInfo.Gross, userInfo.Quota);
            sb.AppendFormat("<dt>书本(花费/配额):</dt><dd>{0}本/{1}本</dd>", userInfo.GrossBooks, userInfo.QuotaBooks);
            sb.AppendFormat("<dt>QQ:</dt><dd>{0}</dd>", userInfo.Qq);
            sb.AppendFormat("<dt>Email:</dt><dd>{0}</dd>", userInfo.Mail);
            sb.AppendFormat("<dt>注册时间:</dt><dd>{0}</dd>", userInfo.Date.ToLongDateString());
            sb.AppendFormat("<dt>地址:</dt><dd>{0}</dd>", userInfo.From);
            sb.AppendFormat("<dt>浏览器</dt><dd>{0}{1}</dd>", Request.Browser.Browser, Request.Browser.Version);
            sb.AppendFormat("<dt>上次登陆IP:</dt><dd>{0}</dd>", userSession.LastIp);
            sb.AppendFormat("<dt>上次登陆时间:</dt><dd>{0}</dd>", userSession.LastDate);
            sb.Append("</dl>");

            userLb.Text = sb.ToString();

            if (userInfo.GrossBooks >= userInfo.QuotaBooks)
            {
                addNewLb.Text = "你的书本量被限制";
                addNewLb.Enabled = false;
            }


        }
        protected void addNewLb_Click(object sender, EventArgs e)
        {
            Session["Action"] = (int)BookAction.AddOne;
            Response.Redirect("DefaultSet.xhtml");
        }
        protected void allBookLb_Click(object sender, EventArgs e)
        {
            MultiPlace.ActiveViewIndex = 0;
            Session["ActiveViewIndex"] = 0;
        }
        protected void favoriteBtn_Click(object sender, EventArgs e)
        {
            MultiPlace.ActiveViewIndex = 1;
            Session["ActiveViewIndex"] = 1;
        }
        protected void changeUerInfo_Click(object sender, EventArgs e)
        {
            MultiPlace.ActiveViewIndex = 2;
            Session["ActiveViewIndex"] = 2;
        }
        protected void changeUserPwd_Click(object sender, EventArgs e)
        {
            MultiPlace.ActiveViewIndex = 3;
            Session["ActiveViewIndex"] = 3;
        }
       
}
}